import { network } from '@/utils';
import { TableListParams } from './data.d';

import { partner } from '../../../../../config/Apis';

export async function queryContractDetail(params: TableListParams) {
  params._content_type = 'json';
  return network.get(partner.contract_detail, {
    params,
  });
}

export async function queryPartnersList(params: TableListParams) {
  params._content_type = 'json';
  return network.get(partner.franchisee_list, {
    params,
  });
}

export async function queryContractSubjectList(params: TableListParams) {
  return network.get(partner.common_org_list, {
    params,
  });
}

export async function queryContractTypeDetail(params: TableListParams) {
  params._content_type = 'json';
  return network.get(partner.contract_add, {
    params,
  });
}

export async function checkContract(params: any) {
  return network.get(partner.contract_is_contract_num_unique, {
    params,
  });
}

export async function queryReimbursement(params: any) {
  return network.get(partner.contract_get_repayment_info, {
    params,
  });
}

export async function addContract(params: any) {
  let ApiPath = '';
  switch (params.contract_type) {
    case 1:
      ApiPath = params.id ? partner.contract_update_franchise : partner.contract_save_franchise;
      break;
    case 2:
      ApiPath = params.id ? partner.contract_update_sale : partner.contract_save_sale;
      break;
    case 3:
      ApiPath = params.id ? partner.contract_update_loan : partner.contract_save_loan;
      break;
    default:
      ApiPath = params.id ? partner.contract_update_franchise : partner.contract_save_franchise;
  }
  return network.post(ApiPath, {
    params,
  });
}

export async function uploadContract(params: any) {
  return network.post(partner.franchisee_upload_file, {
    params,
  });
}

export async function querySaleInfo(params: {contract_id: number}) {
  return network.get(partner.contract_sale_contract_info, {
    params,
  });
}
